﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace HRdex_Final.Forms
{
    public partial class Form : System.Web.UI.MasterPage
    {
        string SessionID()
        {

            return Session["EmployeeID"].ToString();

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\HRdexDB.mdf;Integrated Security=True;User Instance=True");
            SqlCommand cmdAdmin = new SqlCommand("SELECT        formEmployees.EmployeeID, catUserLevel.catUserLevelName AS [User Level], catPositions.catPositionsName AS Position, "+
                         " catDepartment.DepartmentName AS Department, catCollege.CollegeName AS Office "+
                         " FROM            formEmployees INNER JOIN "+
                         " catDepartment ON formEmployees.DeptID = catDepartment.DeptID INNER JOIN "+
                         " catCollege ON formEmployees.CollegeID = catCollege.CollegeID INNER JOIN "+
                         " catPositions ON formEmployees.catPositionsID = catPositions.catPositionsID INNER JOIN "+
                         " catUserLevel ON formEmployees.UserLevelID = catUserLevel.UserLevelID WHERE formEmployees.EmployeeID = " + SessionID(), conn);
            SqlDataAdapter daAdmin = new SqlDataAdapter(cmdAdmin);
            DataTable dtAdmin = new DataTable("dtAdmin");
            daAdmin.Fill(dtAdmin);
            if (dtAdmin.Rows[0].ItemArray[1].ToString() == "Faculty")
            {
                Menu.Visible = false;
                Menu1.Visible = true;
            }
            else if (dtAdmin.Rows[0].ItemArray[1].ToString() == "Employee")
            {  

                Menu.Items.RemoveAt(4);
                Menu.Items.RemoveAt(3);
                Menu1.Visible = false;
            }

            if (dtAdmin.Rows[0].ItemArray[1].ToString() == "Admin" || dtAdmin.Rows[0].ItemArray[1].ToString() == "SubAdmin")
            {
                Menu.Visible = false;
                Menu1.Visible = false;
            }
            else if (dtAdmin.Rows[0].ItemArray[1].ToString() == "Faculty" && dtAdmin.Rows[0].ItemArray[2].ToString() == "Chairperson" || dtAdmin.Rows[0].ItemArray[2].ToString() == "Head" || dtAdmin.Rows[0].ItemArray[2].ToString() == "Dean")
            {
                Menu.Visible = false;
                Menu1.Visible = false;
            }
            else if (dtAdmin.Rows[0].ItemArray[1].ToString() == "Employee" && dtAdmin.Rows[0].ItemArray[2].ToString() == "Head" || dtAdmin.Rows[0].ItemArray[2].ToString() == "Supervisor" || dtAdmin.Rows[0].ItemArray[2].ToString() == "Director")
            {
                Menu.Visible = false;
                Menu1.Visible = false;
            }
            else if (dtAdmin.Rows[0].ItemArray[1].ToString() == "Faculty" && dtAdmin.Rows[0].ItemArray[2].ToString() == "Chairperson" || dtAdmin.Rows[0].ItemArray[2].ToString() == "Head" || dtAdmin.Rows[0].ItemArray[2].ToString() == "Dean")
            {
                Menu.Visible = false;
                Menu1.Visible = false;
            }
            else if (dtAdmin.Rows[0].ItemArray[1].ToString() == "Faculty")
            {
                MenuAdmin.Visible = false;
                Menu.Items[1].Enabled = false;
            }
            else if (dtAdmin.Rows[0].ItemArray[1].ToString() == "Employee")
            {
                MenuAdmin.Visible = false;
                Menu.Items[3].Enabled = false;
                Menu.Items[4].Enabled = false;
            }

        }



    }
}